<?php
class UrlManager extends CUrlManager
{
    public function createUrl($route,$params=array(),$ampersand='&')
    {
        /*if (!isset($params['language'])) {
            echo "OK<br>";
            if (Yii::app()->user->hasState('language'))
            {
                echo "OK<br>";
                echo Yii::app()->language = Yii::app()->user->getState('language');
            }
            else if(isset(Yii::app()->request->cookies['language']))
                Yii::app()->language = Yii::app()->request->cookies['language']->value;
            $params['language']=Yii::app()->language;
        }
        return parent::createUrl($route, $params, $ampersand);*/
        /*echo '$route=>'.$route."<br>";
        echo '$params'."<br>";
        echo "<pre>";
        print_r($params);
        echo "</pre>";
        echo '$ampersands=>'.$ampersand."<br>";*/
        if(!isset($params['language'])){
            //echo "No params language<br>";
            if (Yii::app()->user->hasState('language'))
            {
                //echo "Exist<br>";
                Yii::app()->language = Yii::app()->user->getState('language');
            }
            else if(isset(Yii::app()->request->cookies['language']))
                Yii::app()->language = Yii::app()->request->cookies['language']->value;
            //$params['language']=Yii::app()->language;
            
            return parent::createUrl($route, $params, $ampersand);
        }
    }
}
?>